﻿// -----------------------------------------------------------------------
// <copyright file="Log4netConfig.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace BasicFrameworkDemo.Utility
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;

    using log4net;


    public enum Log4NetType
    {
        /// <summary>
        /// The Debug
        /// </summary>
        /// Creator:zhouchao
        /// Creation Date:6/8/2012 7:28 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        Debug,

        /// <summary>
        /// The Error
        /// </summary>
        /// Creator:zhouchao
        /// Creation Date:6/8/2012 7:28 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        Error,

        /// <summary>
        /// The Info
        /// </summary>
        /// Creator:zhouchao
        /// Creation Date:6/8/2012 7:28 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        Info,

        /// <summary>
        /// The Fatal
        /// </summary>
        /// Creator:zhouchao
        /// Creation Date:6/8/2012 7:28 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        Fatal,

        /// <summary>
        /// The Warn
        /// </summary>
        /// Creator:zhouchao
        /// Creation Date:6/8/2012 7:28 PM
        /// Modifier:
        /// Last Modified:
        /// ----------------------------------------------------------------------------------------
        Warn
    }
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    /// <author>
    /// LiLei
    /// </author>
    public class Log4NetUtility
    {

        private static readonly Log4NetUtility Log4NetInstance;

        private Log4NetUtility()
        {
        }

        public static Log4NetUtility GetInstance()
        {
            return Log4NetInstance ?? new Log4NetUtility();
        }

        /// <summary>
        /// Configs this instance.
        /// </summary>
        /// Creator:LiLei
        /// CreationDate:6/27/2012 11:16 AM
        /// Modify:
        /// ModifyDate:
        /// ----------------------------------------------------------------------------------------
        public void Config()
        {
            var configPath = SystemConfig.Log4NetCfgPath ?? string.Empty;
            var filePath = string.Format("{0}/{1}", AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\', '/'), configPath.TrimStart('\\', '/'));
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(filePath));
        }

        /// <summary>
        /// Gets the log.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        /// Creator:LiLei
        /// CreationDate:6/27/2012 11:16 AM
        /// Modify:
        /// ModifyDate:
        /// ----------------------------------------------------------------------------------------
        public ILog GetLogger(string name)
        {
            var logger = LogManager.GetLogger(name);
            return logger;
        }
    }

}
